import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router);
var Routers = new Router({
  // mode: 'history',
  mode: 'hash',
  routes: [
    // 错误页面重定向到404页面
    { path: "*", redirect: "404" },
    {
      path: "/404",
      component: resolve => require(['src/views/help/404/404.vue'], resolve),
    },
    // 重定向
    // { path: '/', redirect: 'src/views/Login/Login.vue' },
    {
      path: '/',
      component: resolve => require(['src/views/login/login.vue'], resolve)
    },
    {
      path: '/index',
      component: resolve => require(['src/views/common/xheader/xheader.vue'], resolve),
      children: [
        //======系统管理开始=======
        
        {
          path: '/operate-manage/activity-list',
          component: resolve => require(['views/operate-manage/activity-list/activity-list.vue'], resolve)
        },
        // 用户管理
        {
          path: '/system/member',
          component: resolve => require(['views/system/member/member.vue'], resolve)
        },
        // 社区管理
        {
          path: '/system/community',
          component: resolve => require(['views/system/community/community.vue'], resolve)
        },
        // 网格管理
        {
          path: '/system/grid',
          component: resolve => require(['views/system/grid/index.vue'], resolve)
        },
        // 小区管理
        {
          path: '/system/complex',
          component: resolve => require(['views/system/complex/index.vue'], resolve)
        },
        // 部门管理
        {
          path: '/system/department',
          component: resolve => require(['views/system/department/index.vue'], resolve)
        },
        // 街道管理
        {
          path: '/system/street',
          component: resolve => require(['views/system/street/street.vue'], resolve)
        },
        // 统计
        {
          path: '/statistics/index',
          component: resolve => require(['views/statistics/index.vue'], resolve)
        },
        // 微民情
        {
          path: '/minqing/index',
          component: resolve => require(['views/minqing/index.vue'], resolve)
        },
        // 微检查
        {
          path: '/check/index',
          component: resolve => require(['views/check/index.vue'], resolve)
        },
         // 微宣教
        {
          path: '/pae/class',
          component: resolve => require(['views/pae/pae-class/index.vue'], resolve)
        },
         // 微宣教
        {
          path: '/pae/index',
          component: resolve => require(['views/pae/index.vue'], resolve)
        },
         //微调查
         {
          path: '/question/index',
          component: resolve => require(['views/question/index.vue'], resolve)
        },
      ]
    },
  ]
})

//路由守卫方法
Routers.beforeEach((to, from, next) => {
  if (to.path == '/404') {
    next()
    return
  }
  //保存当前路径地址
  Vue.prototype.ModelData.xNewPath = to.path;
  for (let i = 0; i < Vue.prototype.ModelData.xLeftTitle.length; i++) {
    Vue.prototype.ModelData.xLeftTitle[i].isActive = false;
    for (let j = 0; j < Vue.prototype.ModelData.xLeftTitle[i].children.length; j++) {
      if (Vue.prototype.ModelData.xLeftTitle[i].children[j].url == to.path) {
        Vue.prototype.ModelData.xLeftTitle[i].isShow = true;
        Vue.prototype.ModelData.xLeftTitle[i].isActive = true;
        Vue.prototype.ModelData.xLeftTitle[i].children[j].isActive = true;
      } else {
        Vue.prototype.ModelData.xLeftTitle[i].children[j].isActive = false;
      }
    }
  }
  next();
})

export default Routers